package com.example.demo.GeneralResponse;

import java.io.Serializable;

/**
 * @version: V0.3
 * @author: 郑皓杰 吴嘉鑫
 * @className: APIResponse
 * @packageName: com.example.demo.GeneralResponse
 * @description: 这是统一返回类型
 * @data: 2021-07-15
 **/
public class APIResponse<T> implements Serializable {

	private static final long serialVersionUID = 1L;

	private int code;
	private String message;
	private T data;
	
	private APIResponse(int code,String message,T data){
		this.code=code;
		this.message=message;
		this.data=data;
	}
	
	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public static <T> APIResponse<T> success(String message,T data) {
        APIResponse<T> response = new APIResponse<T>(0,message,data);
        return response;
    }

    public static <T> APIResponse<T> success() {
        return success("",null);
    }

    public static <T> APIResponse<T> fail(String message) {
        APIResponse<T> response = new APIResponse<T>(-1,message,null);
        return response;
    }

    public static <T> APIResponse<T> fail() {
        return fail("failure");
    }
}
